import $ from 'jquery'
import { prefix } from '../config/api'

export const get = url => $.get(prefix + url)
export const post = (url, data = {}) => $.post(prefix + url, data)
export const put = (url, data = {}) => $.ajax({ url: prefix + url, type: 'put', data })
export const del = (url, data = {}) => $.ajax({ url: prefix + url, type: 'delete', data })

function request(url, type, data, header) {
  let requestConfig = {
    url,
    type,
    headers: {
      ...header
    }
  }
  if (type != 'get') requestConfig = { ...requestConfig, data }
  return $.ajax(requestConfig)
}